package thread;
/*
 * 
 * 	1. 继承Thread类
	2. 实现Runnable接口
	3. 匿名类的方式

注： 启动线程是start()方法，run()并不能启动一个新的线程
 */
public class TestThread {
	public static void main(String[] args) {
		final Hero doomFist=new Hero();
		doomFist.name="末日铁拳";
		doomFist.hp=250;
		doomFist.damage=40;
		
		final Hero genji=new Hero();
		genji.name="源氏";
		genji.hp=200;
		genji.damage=120;
		
		final Hero reinHart=new Hero();
		reinHart.name="莱因哈特";
		reinHart.hp=500;
		reinHart.damage=80;
		
		final Hero lucio=new Hero();
		lucio.name="卢西奥";
		lucio.hp=200;
		lucio.damage=30;
		
//		//单线程
//		while (!genji.isDead()) {
//			doomFist.attackHero(genji);
//		}
//		
//		while (!reinHart.isDead()) {
//			lucio.attackHero(reinHart);
//		}
		
//		//多线程extends Thread
//		KillThread killThread1=new KillThread(doomFist, genji);
//		KillThread killThread2=new KillThread(lucio, reinHart);
//		killThread1.start();
//		killThread2.start();
		 
//		//多线程implement Runnable
//		Battle battle1=new Battle(doomFist, genji);
//		Battle battle2=new Battle(lucio, reinHart);
//		new Thread(battle1).start();
//		new Thread(battle2).start();
		
		//匿名类创建多线程
		Thread t1=new Thread() {
			public void run() {
				Thread.yield();
				while (!genji.isDead()) {
					doomFist.attackHero(genji);
				}
			}
		};
		Thread t2=new Thread() {
			public void run() {
				while (!reinHart.isDead()) {
					lucio.attackHero(reinHart);
				}
			}
		};
		t2.setDaemon(true);
		t1.setPriority(5);
		t1.setPriority(5);
		t1.start();
		t2.start();
	}
}
